package com.example.skycode5.servlet;

import com.example.skycode5.bean.NewsBean;
import com.example.skycode5.dao.NewsDao;
import jakarta.servlet.ServletException;
import jakarta.servlet.annotation.WebServlet;
import jakarta.servlet.http.HttpServlet;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;

import java.io.IOException;

/**
 * 1.接收post网址/newsAdd的请求
 * 2.接收到传递过来的新闻参数 新闻标题 新闻内容
 * 3.完成新闻的添加
 * 4.跳转到其他页面
 */
@WebServlet("/NnewsAdd")
public class NoticeAddServlet extends HttpServlet {
    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        req.setCharacterEncoding("UTF-8");
        String nwesTitle = req.getParameter("newsTitle");
        String nwesContent = req.getParameter("newsContent");
        NewsBean newsBean = new NewsBean();//实例化新闻对象
        newsBean.setNewsTitle(nwesTitle);//设置新闻标题
        newsBean.setNewsContent(nwesContent);//设置新闻内容
        NewsDao newsDao = new NewsDao();//实例化 新闻Dao对象
        newsDao.add(newsBean);//调用新闻Dao的添加方法 传递新闻对象
        //在Servlet有页面重定向功能 可以将页面跳转到指定位置

    }
}
